#include "types.h"
#include "stat.h"
#include "user.h"


int
main(int argc, char *argv[])
{
	int i = 0;
	int j = 0;
	int pid = 0;
	int PROCS = 1;
	int sem_id = binary_sem_create();


	while (i<PROCS){
		pid = fork();
		i++;
	}


	if (pid!=0){
		for (i=0; i<10; i++)
			printf(1, "bad motherfucker!\n");
	}

/*
int binary_sem_create(void);
int binary_sem_down(int);
int binary_sem_up(int);
*/

	printf(2, "process %d is trying to aquire semaphore\n", thread_getProcId());
	binary_sem_down(sem_id);

	if(pid != 0){
		while (j<10){
			printf(1,"hello\n");
			printf(1,"hello\n");
			printf(1,"hello\n");
			printf(1,"hello\n");
			printf(1,"hello\n");
			j++;
		}
	}
	else{
		while (j<10){
			printf(1,"goodbye\n");
			printf(1,"goodbye\n");
			printf(1,"goodbye\n");
			printf(1,"goodbye\n");
			printf(1,"goodbye\n");
			j++;
		}
	}

	binary_sem_up(sem_id);

	if(pid!=0)
		wait();
	exit();
}

